const { $Toast } = require('../../dist/base/index');
Page({
  data: {
    // 登陆的用户信息
    userInfo: {},
    // 选项卡数据
    cardList: [
      { id: "1", url: `/pages/home/system/index?name="&{userInfo.nickName}&params=system`, icon: "iconfont icon-zhiduchaxun", title: "我的千分制" },
      { id: "2", url: "/pages/home/works/index?params=works", icon: "iconfont icon-zuopin", title: "我的作品" },
      { id: "3", url: "/pages/home/achievement/index?params=achievement", icon: "iconfont icon-chengjichaxun", title: "我的成绩" },
      { id: "6", url: "/pages/home/service/index?params=service", icon: "iconfont icon-kefu", title: "联系客服" },
      { id: "4", url: "/pages/mine/set/index?params=set", icon: "iconfont icon-shezhi1", title: "设置" },
      // { id: "5", url: "/pages/mine/logout/index", icon: "iconfont icon-tuichudenglu", title: "退出此账号" },
    ],
    // 确认对话框 展示、隐藏
    visible: false,
    // 对话框数据
    actions: [
      {
        name: '取消'
      },
      {
        name: '确定',
        color: '#ed3f14',
        loading: false
      }
    ]
  },
  // 点击登录
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        this.setData({ userInfo: res.userInfo })
        wx.setStorageSync("userInfo", res.userInfo);
      }
    })
  },
  // 点击退出 展示对话框
  logout() {
    this.setData({ visible: true })
  },
  // 处理退出事件
  handleModalClick({ detail }) {
    try {
      if (detail.index === 0) {
        this.setData({
          visible: false
        });
      } else {
        const action = [...this.data.actions];
        action[1].loading = true;

        this.setData({
          actions: action
        });

        setTimeout(() => {
          action[1].loading = false;
          this.setData({
            visible: false,
            actions: action,
            userInfo: {}
          });
          wx.removeStorageSync("userInfo")
        }, 1000);
      }
    } catch (err) { console.log(err) }
  }

  // logout(){
  //   this.setData({userInfo: {}})
  //   wx.removeStorageSync("userInfo")
  // }
})